//
//  SunBindSuccessVC.m
//  Xspcf
//
//  Created by sunshine on 2017/7/4.
//  Copyright © 2017年 小小算盘. All rights reserved.
//

#import "SunBindSuccessVC.h"
#import "JxWebVC.h"

@interface SunBindSuccessVC ()

@end

@implementation SunBindSuccessVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"开通成功";
    self.view.backgroundColor = BACKGROUND;
    [self creatUI];
    [self requestToUser];
    // Do any additional setup after loading the view.
}

- (BOOL)navigationShouldPopOnBackButton{
    [self.navigationController popToRootViewControllerAnimated:YES];
    return false;
}

- (void)setPassword{
    NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_PASSWORD];
    [[Sun shareSun]showActivity:self];
    [HttpRequest postURL:url withParam:nil success:^(id requestDic, NSString *msg) {
        [[Sun shareSun]hideActivity];
        JxWebVC *web = [[JxWebVC alloc]init];
        web.param = [requestDic objectForKey:@"data"];
        web.url = [requestDic objectForKey:@"url"];
        web.title = @"设置存管交易密码";
        [self.navigationController pushViewController:web animated:YES];
    } failure:^(NSString *errorInfo, int code) {
        [[Sun shareSun]hideActivity];
        [[Sun shareSun]showMsg:errorInfo];
    }];
}

- (void)requestToUser{
    NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_USERINFO];
    [[Sun shareSun]showActivity:self];
    [HttpRequest postURL:url withParam:nil success:^(id requestDic, NSString *msg) {
        [[Sun shareSun]hideActivity];
        [Sun setUser:requestDic forKey:USER];
        UILabel *l1 = (UILabel *)[self.view viewWithTag:1];
        UILabel *l2 = (UILabel *)[self.view viewWithTag:2];
        UILabel *l3 = (UILabel *)[self.view viewWithTag:3];
        l1.text = [NSString stringWithFormat:@"开户银行：%@",[requestDic objectForKey:@"jxBank"]];
        l2.text = [NSString stringWithFormat:@"开户姓名：%@",[requestDic objectForKey:@"name"]];
        l3.text = [NSString stringWithFormat:@"开户账户：%@",[requestDic objectForKey:@"jxCard"]];
    } failure:^(NSString *errorInfo, int code) {
        [[Sun shareSun]hideActivity];
        [[Sun shareSun]showMsg:errorInfo];
    }];
}

- (void)creatUI{
    UIImageView *img = [[UIImageView alloc]init];
    [self.view addSubview:img];
    [img lt_XcenterTo:nil save:YES];
    [img lt_setTop:Y(42) to:nil save:YES];
    [img lt_setSize:CGSizeMake(X(52), X(52)) save:YES];
    img.image = [UIImage imageNamed:@"tool_success"];
    UILabel *l1 = [[UILabel alloc]init];
    [self.view addSubview:l1];
    [l1 lt_XcenterTo:nil save:YES];
    [l1 lt_setTop:Y(16) to:img save:YES];
    l1.textColor = GRAY;
    l1.text = @"银行存管账号开通成功";
    if (self.bind) {
        l1.text = @"绑卡成功";
        self.title = @"绑卡成功";
    }
    UIView *view = [[UIView alloc]init];
    [self.view addSubview:view];
    [view lt_Top:SunEdgesMake(Y(36), 0, 0, Y(167)) to:l1 save:YES];
    view.backgroundColor = WHITE;
    UILabel *l2 = [[UILabel alloc]init];
    [view addSubview:l2];
    l2.textColor = BLACK;
    l2.tag = 1;
    l2.text = @"开户银行：";
    [l2 lt_setTop:Y(36) to:nil save:NO];
    [l2 lt_setLeft:X(30) to:nil save:NO];
    UILabel *l3 = [Sun copyWithView:l2];
    [view addSubview:l3];
    l3.tag = 2;
    l3.text = @"开户姓名：";
    [l3 lt_setTop:Y(20) to:l2  save:NO];
    [l3 lt_leftEqual:l2 save:NO];
    UILabel *l4 = [Sun copyWithView:l2];
    [view addSubview:l4];
    l4.tag = 3;
    l4.text = @"电子账户：";
    [l4 lt_setTop:Y(20) to:l3  save:NO];
    [l4 lt_leftEqual:l2 save:NO];
    UIButton *btn = [[UIButton alloc]init];
    [self.view addSubview:btn];
    [btn lt_Top:SunEdgesMake(Y(40), X(15), X(15), Y(44)) to:view save:YES];
    btn.clipsToBounds = YES;
    [btn setBackgroundColor:BLUE forState:UIControlStateNormal];
    [btn setBackgroundColor:[HXColor colorWithHexString:@"87CEFA"] forState:UIControlStateHighlighted];
    btn.layer.cornerRadius = 4;
    [btn setTitle:@"设置交易密码" forState:UIControlStateNormal];
    [btn setTitleColor:WHITE forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:17];
    [btn addTarget:self action:@selector(setPassword) forControlEvents:UIControlEventTouchUpInside];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
